package com.mdlib.droid.module.main;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.mdlib.droid.R;
import com.mdlib.droid.base.BaseAppActivity;
import com.mdlib.droid.module.home.fragment.HomeFragment;
import com.mdlib.droid.module.home.fragment.MyFragment;
import com.mdlib.droid.widget.CustomViewPager;
import com.mdlib.droid.widget.tab.AlphaTabsIndicator;

import java.util.ArrayList;

import butterknife.BindArray;
import butterknife.BindView;

public class MainActivity extends BaseAppActivity {


    @BindView(R.id.cvp_main_top)
    CustomViewPager mCvpMainTop;
    @BindView(R.id.atl_main_tab)
    AlphaTabsIndicator mAtlMainTab;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    @BindArray(R.array.main_tab_txt)
    String[] mTextviewArray;


    @Override
    protected int getContentViewId() {
        return com.mdlib.droid.R.layout.activity_main;
    }

    @Override
    protected void initView() {
        super.initView();
        MainAdapter mainAdapter = new MainAdapter(getSupportFragmentManager());
        mCvpMainTop.setScanScroll(true);
        mCvpMainTop.setAdapter(mainAdapter);
        mAtlMainTab.setViewPager(mCvpMainTop);
        mAtlMainTab.setTabCurrenItem(0);

    }


    private class MainAdapter extends FragmentPagerAdapter {


        public MainAdapter(FragmentManager fm) {
            super(fm);
            mFragments.add(HomeFragment.newInstance());
            mFragments.add(MyFragment.newInstance());
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }


    }

}
